<?php
	class Controller_Games extends Controller_Base
	{
		function index()
		{
			
		}
		function new_games()
		{
			$this->assignData('genres', WebApp::app()->db->select(array('*'),array('genres')));
			if	(	
					isset($_POST['g_genre']) and 
					isset($_POST['btnAdd']) and 
					isset($_POST['g_name']) and 
					isset($_POST['g_descr']) and
					isset($_FILES['g_icon']['name'])
				)
			{				
				$file = $_FILES['g_icon'];
				WebApp::app()->db->insert	("games", array(	"name"=>$_POST['g_name'],
																"descr"=>$_POST['g_descr'],
																"icon"=>$_FILES['g_icon']['name']
															)
											);
				$idGame = WebApp::app()->db->select(array("max(id) as maxID"),array("games"));
				$idGame = $idGame[0]->maxID;
				WebApp::app()->db->insert("genres_games", array("id_genre"=>$_POST['g_genre'], "id_game"=>$idGame));
				WebApp::app()->image_resize($file['tmp_name'], "../images/galery/game_icon/mini/".$file['name'],156,125);
				copy ($file['tmp_name'], "../images/galery/game_icon/".$file['name']);
				header("Location:".$this->baseUrl."successAdd");
			}
		}
		function successAdd()
		{
			
		}
	}
?>